home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1997 January: Mac OS SDK / Dev.CD Jan 97 SDK2.toast / Development Kits (Disc 2) / OpenDoc Development Framework / ODFDev / ODF / Found / FWString / FWBndStr.cpp < prev    next >
Encoding:
Text File  |  1996-09-17  |  8.0 KB  |  242 lines  |  [TEXT/MPS ]

  1. //========================================================================================
  2. //
  3. //    File:                FWBndStr.cpp
  4. //    Release Version:    $ ODF 2 $
  5. //
  6. //    Copyright:    (c) 1993 - 1996 by Apple Computer, Inc., all rights reserved.
  7. //
  8. //========================================================================================
  9.  
  10. #include "FWFound.hpp"
  11.  
  12. #ifndef FWBNDSTR_H
  13. #include "FWBndStr.h"
  14. #endif
  15.  
  16. #ifdef FW_BUILD_MAC
  17. #include <Types.h>
  18. #endif
  19.  
  20. #ifndef FWEXCLIB_H
  21. #include "FWExcLib.h"
  22. #endif
  23.  
  24. #ifndef FWPRIDEB_H
  25. #include "FWPriDeb.h"
  26. #endif
  27.  
  28. #ifndef FWSTREAM_H
  29. #include "FWStream.h"
  30. #endif
  31.  
  32. #ifndef FWEXCEPT_H
  33. #include "FWExcept.h"
  34. #endif
  35.  
  36. //========================================================================================
  37. // File scope definitions
  38. //========================================================================================
  39.  
  40. #ifdef FW_BUILD_MAC
  41. #pragma segment Strings
  42. #endif
  43.  
  44. //========================================================================================
  45. //    CLASS FW_CString32
  46. //========================================================================================
  47.  
  48. FW_DEFINE_AUTO(FW_CString32)
  49. FW_DEFINE_CLASS_M1(FW_CString32,    FW_CString)
  50.  
  51. // This class is archivable, but we provide the archiving implementation in a separate
  52. // translation unit in order to enable deadstripping of the archiving-related code
  53. // in parts that do not use archiving with this class.
  54.  
  55. //----------------------------------------------------------------------------------------
  56. //    FW_CString32::FW_CString32
  57. //----------------------------------------------------------------------------------------
  58.  
  59. FW_CString32::FW_CString32() :
  60.     FW_CString(FW_PrivString_NewRepWithStaticBuffer(fBuffer, sizeof(fBuffer)))
  61. {
  62.     FW_END_CONSTRUCTOR
  63. }
  64.  
  65. //----------------------------------------------------------------------------------------
  66. //    FW_CString32::FW_CString32
  67. //----------------------------------------------------------------------------------------
  68.  
  69. FW_CString32::FW_CString32(const FW_CString32 &string) :
  70.     FW_CString(FW_PrivString_NewRepWithStaticBuffer(fBuffer, sizeof(fBuffer)))
  71. {
  72.     ReplaceAll(string);
  73.     FW_END_CONSTRUCTOR
  74. }
  75.  
  76. //----------------------------------------------------------------------------------------
  77. //    FW_CString32::FW_CString32
  78. //----------------------------------------------------------------------------------------
  79.  
  80. FW_CString32::FW_CString32(const FW_CString &string) :
  81.     FW_CString(FW_PrivString_NewRepWithStaticBuffer(fBuffer, sizeof(fBuffer)))
  82. {
  83.     ReplaceAll(string);
  84.     FW_END_CONSTRUCTOR
  85. }
  86.  
  87. //----------------------------------------------------------------------------------------
  88. //    FW_CString32::FW_CString32
  89. //----------------------------------------------------------------------------------------
  90.  
  91. FW_CString32::FW_CString32(const FW_Char *bytes, FW_ByteCount numberBytes) :
  92.     FW_CString(FW_PrivString_NewRepWithStaticBuffer(fBuffer, sizeof(fBuffer)))
  93. {
  94.     ReplaceAll(bytes, numberBytes);
  95.     FW_END_CONSTRUCTOR
  96. }
  97.  
  98. //----------------------------------------------------------------------------------------
  99. //    FW_CString32::FW_CString32
  100. //----------------------------------------------------------------------------------------
  101.  
  102. FW_CString32::FW_CString32(const FW_Char *items) :
  103.     FW_CString(FW_PrivString_NewRepWithStaticBuffer(fBuffer, sizeof(fBuffer)))
  104. {
  105.     ReplaceAll(items);
  106.     FW_END_CONSTRUCTOR
  107. }
  108.  
  109. //----------------------------------------------------------------------------------------
  110. //    FW_CString32::~FW_CString32
  111. //----------------------------------------------------------------------------------------
  112.  
  113. FW_CString32::~FW_CString32()
  114. {
  115.     FW_START_DESTRUCTOR
  116.     FW_PlatformError error;
  117.     FW_PrivString_ReleaseStaticBuffer(fRep, &error);
  118.     FW_PRIV_ASSERT(error == 0);
  119.     //
  120.     // If an error is returned from above then we may be in BIG trouble.
  121.     // The problem is that throwing exceptions from destructors is dangerous.
  122.     // If the destructor has been called due to stack unwinding from a previous
  123.     // exception, then throwing the exception from the destructor will call
  124.     // terminate().  Note that ReleaseStaticBuffer will only fail if it was
  125.     // impossible to allocate a block of 40 bytes.
  126.     //
  127.     FW_FailOnError(error);
  128. }
  129.  
  130. //----------------------------------------------------------------------------------------
  131. //    FW_CString32::operator=
  132. //----------------------------------------------------------------------------------------
  133.  
  134. FW_CString32& FW_CString32::operator=(const FW_CString32& other)
  135. {
  136.     if (&other != this)
  137.     {
  138.         ReplaceAll(other);
  139.     }
  140.     return *this;
  141. }
  142.  
  143. //========================================================================================
  144. //    CLASS FW_CString255
  145. //========================================================================================
  146.  
  147. FW_DEFINE_AUTO(FW_CString255)
  148. FW_DEFINE_CLASS_M1(FW_CString255,    FW_CString)
  149.  
  150. // This class is archivable, but we provide the archiving implementation in a separate
  151. // translation unit in order to enable deadstripping of the archiving-related code
  152. // in parts that do not use archiving with this class.
  153.  
  154. //----------------------------------------------------------------------------------------
  155. //    FW_CString255::FW_CString255
  156. //----------------------------------------------------------------------------------------
  157.  
  158. FW_CString255::FW_CString255() :
  159.     FW_CString(FW_PrivString_NewRepWithStaticBuffer(fBuffer, sizeof(fBuffer)))
  160. {
  161.     FW_END_CONSTRUCTOR
  162. }
  163.  
  164. //----------------------------------------------------------------------------------------
  165. //    FW_CString255::FW_CString255
  166. //----------------------------------------------------------------------------------------
  167.  
  168. FW_CString255::FW_CString255(const FW_CString255 &string) :
  169.     FW_CString(FW_PrivString_NewRepWithStaticBuffer(fBuffer, sizeof(fBuffer)))
  170. {
  171.     ReplaceAll(string);
  172.     FW_END_CONSTRUCTOR
  173. }
  174.  
  175. //----------------------------------------------------------------------------------------
  176. //    FW_CString255::FW_CString255
  177. //----------------------------------------------------------------------------------------
  178.  
  179. FW_CString255::FW_CString255(const FW_CString &string) :
  180.     FW_CString(FW_PrivString_NewRepWithStaticBuffer(fBuffer, sizeof(fBuffer)))
  181. {
  182.     FW_END_CONSTRUCTOR
  183.     ReplaceAll(string);
  184. }
  185.  
  186. //----------------------------------------------------------------------------------------
  187. //    FW_CString255::FW_CString255
  188. //----------------------------------------------------------------------------------------
  189.  
  190. FW_CString255::FW_CString255(const FW_Char *bytes, FW_ByteCount numberBytes) :
  191.     FW_CString(FW_PrivString_NewRepWithStaticBuffer(fBuffer, sizeof(fBuffer)))
  192. {
  193.     ReplaceAll(bytes, numberBytes);
  194.     FW_END_CONSTRUCTOR
  195. }
  196.  
  197. //----------------------------------------------------------------------------------------
  198. //    FW_CString255::FW_CString255
  199. //----------------------------------------------------------------------------------------
  200.  
  201. FW_CString255::FW_CString255(const FW_Char *items) :
  202.     FW_CString(FW_PrivString_NewRepWithStaticBuffer(fBuffer, sizeof(fBuffer)))
  203. {
  204.     ReplaceAll(items);
  205.     FW_END_CONSTRUCTOR
  206. }
  207.  
  208. //----------------------------------------------------------------------------------------
  209. //    FW_CString255::~FW_CString255
  210. //----------------------------------------------------------------------------------------
  211.  
  212. FW_CString255::~FW_CString255()
  213. {
  214.     FW_START_DESTRUCTOR
  215.     FW_PlatformError error;
  216.     FW_PrivString_ReleaseStaticBuffer(fRep, &error);
  217.     FW_PRIV_ASSERT(error == 0);
  218.     //
  219.     // If an error is returned from above then we may be in BIG trouble.
  220.     // The problem is that throwing exceptions from destructors is dangerous.
  221.     // If the destructor has been called due to stack unwinding from a previous
  222.     // exception, then throwing the exception from the destructor will call
  223.     // terminate().  Note that ReleaseStaticBuffer will only fail if it was
  224.     // impossible to allocate a block of 260 bytes.
  225.     //
  226.     FW_FailOnError(error);
  227. }
  228.  
  229. //----------------------------------------------------------------------------------------
  230. //    FW_CString255::operator=
  231. //----------------------------------------------------------------------------------------
  232.  
  233. FW_CString255& FW_CString255::operator=(const FW_CString255& other)
  234. {
  235.     if (&other != this)
  236.     {
  237.         ReplaceAll(other);
  238.     }
  239.     return *this;
  240. }
  241.  
  242.